#include "recipient.h"

void FUserBase::addUser(CRecipient* user)
{
    if (RecipientList.contains(user->name)) return;
    RecipientList[user->name] = user;
}
void FUserBase::addUserToGroup(QString user, QString group)
{
    if(!RecipientList.contains(user)) return;
    CRecipient *r = RecipientList[user];

    RecipientGroup g;
    if (RecipientGroups.contains(group))
        g = RecipientGroups[group];
    g.push_back(r);
    RecipientGroups[group] = g;

}
void FUserBase::cleanAll()
{
    RecipientGroups.clear();
    QHash<QString,CRecipient*>::iterator i;
    for(i=RecipientList.begin();
        i!= RecipientList.end();
        i++)
    {
        CRecipient *r = *i;
        delete r;
    }
    RecipientList.clear();
};

RecipientGroup FUserBase::members(QString groupName)
{
    if (RecipientGroups.contains(groupName))
        return RecipientGroups[groupName];
    return RecipientGroup();

}

RecipientGroup FUserBase::allUsers()
{
    RecipientGroup result;
    for(QHash<QString,CRecipient*>::iterator i = RecipientList.begin();
        i!= RecipientList.end();
        i++)
    {

        result.push_back(i.value());
    }
    return result;
};
